<!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="robots" content="noodp" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
        <title>在Activiti中实现动态流程（修改流程图重新发布后对正在运行的流程生效） - 豆是不吃豆豉</title><meta name="Description" content="在Activiti中实现动态流程（修改流程图重新发布后对正在运行的流程生效）"><meta property="og:title" content="在Activiti中实现动态流程（修改流程图重新发布后对正在运行的流程生效）" />
<meta property="og:description" content="在Activiti中实现动态流程（修改流程图重新发布后对正在运行的流程生效）" />
<meta property="og:type" content="article" />
<meta property="og:url" content="https://dou-chi.gitee.io/actdynamicprocess/" />
<meta property="og:image" content="https://dou-chi.gitee.io/logo.png"/>
<meta property="article:published_time" content="2020-12-17T18:34:04+08:00" />
<meta property="article:modified_time" content="2020-12-17T18:34:04+08:00" />
<meta name="twitter:card" content="summary_large_image"/>
<meta name="twitter:image" content="https://dou-chi.gitee.io/logo.png"/>

<meta name="twitter:title" content="在Activiti中实现动态流程（修改流程图重新发布后对正在运行的流程生效）"/>
<meta name="twitter:description" content="在Activiti中实现动态流程（修改流程图重新发布后对正在运行的流程生效）"/>
<meta name="application-name" content="豆是不吃豆豉">
<meta name="apple-mobile-web-app-title" content="豆是不吃豆豉"><meta name="theme-color" content="#ffffff"><meta name="msapplication-TileColor" content="#da532c"><link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
        <link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
        <link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png"><link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png"><link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5"><link rel="manifest" href="/site.webmanifest"><link rel="canonical" href="https://dou-chi.gitee.io/actdynamicprocess/" /><link rel="prev" href="https://dou-chi.gitee.io/activiti%E4%BA%8C%E5%88%9D%E5%A7%8B%E5%8C%96/" /><link rel="next" href="https://dou-chi.gitee.io/kettle-paging/" /><link rel="stylesheet" href="/lib/normalize/normalize.min.css"><link rel="stylesheet" href="/css/style.min.css"><link rel="stylesheet" href="/lib/fontawesome-free/all.min.css"><link rel="stylesheet" href="/lib/animate/animate.min.css"><script type="application/ld+json">
    {
        "@context": "http://schema.org",
        "@type": "BlogPosting",
        "headline": "在Activiti中实现动态流程（修改流程图重新发布后对正在运行的流程生效）",
        "inLanguage": "zh-CN",
        "mainEntityOfPage": {
            "@type": "WebPage",
            "@id": "https:\/\/dou-chi.gitee.io\/actdynamicprocess\/"
        },"genre": "posts","keywords": "Activiti","wordcount":  1109 ,
        "url": "https:\/\/dou-chi.gitee.io\/actdynamicprocess\/","datePublished": "2020-12-17T18:34:04+08:00","dateModified": "2020-12-17T18:34:04+08:00","publisher": {
            "@type": "Organization",
            "name": ""},"author": {
                "@type": "Person",
                "name": "豆是不吃豆豉"
            },"description": "在Activiti中实现动态流程（修改流程图重新发布后对正在运行的流程生效）"
    }
    </script></head>
    <body header-desktop="fixed" header-mobile="auto"><script type="text/javascript">(window.localStorage && localStorage.getItem('theme') ? localStorage.getItem('theme') === 'dark' : ('dark' === 'auto' ? window.matchMedia('(prefers-color-scheme: dark)').matches : 'dark' === 'dark')) && document.body.setAttribute('theme', 'dark');</script>

        <div id="mask"></div><div class="wrapper"><header class="desktop" id="header-desktop">
    <div class="header-wrapper">
        <div class="header-title">
            <a href="/" title="豆是不吃豆豉">豆是不吃豆豉</a>
        </div>
        <div class="menu">
            <div class="menu-inner"><a class="menu-item" href="/posts/"> 所有文章 </a><a class="menu-item" href="/tags/"> 标签 </a><a class="menu-item" href="/categories/"> 分类 </a><a class="menu-item" href="https://github.com/dou-chi" rel="noopener noreffer" target="_blank"> github </a><a class="menu-item" href="https://gitee.com/dou-chi" rel="noopener noreffer" target="_blank"> gitee </a><span class="menu-item delimiter"></span><span class="menu-item search" id="search-desktop">
                        <input type="text" placeholder="搜索文章标题或内容..." id="search-input-desktop">
                        <a href="javascript:void(0);" class="search-button search-toggle" id="search-toggle-desktop" title="搜索">
                            <i class="fas fa-search fa-fw"></i>
                        </a>
                        <a href="javascript:void(0);" class="search-button search-clear" id="search-clear-desktop" title="清空">
                            <i class="fas fa-times-circle fa-fw"></i>
                        </a>
                        <span class="search-button search-loading" id="search-loading-desktop">
                            <i class="fas fa-spinner fa-fw fa-spin"></i>
                        </span>
                    </span><a href="javascript:void(0);" class="menu-item theme-switch" title="切换主题">
                    <i class="fas fa-adjust fa-fw"></i>
                </a>
            </div>
        </div>
    </div>
</header><header class="mobile" id="header-mobile">
    <div class="header-container">
        <div class="header-wrapper">
            <div class="header-title">
                <a href="/" title="豆是不吃豆豉">豆是不吃豆豉</a>
            </div>
            <div class="menu-toggle" id="menu-toggle-mobile">
                <span></span><span></span><span></span>
            </div>
        </div>
        <div class="menu" id="menu-mobile"><div class="search-wrapper">
                    <div class="search mobile" id="search-mobile">
                        <input type="text" placeholder="搜索文章标题或内容..." id="search-input-mobile">
                        <a href="javascript:void(0);" class="search-button search-toggle" id="search-toggle-mobile" title="搜索">
                            <i class="fas fa-search fa-fw"></i>
                        </a>
                        <a href="javascript:void(0);" class="search-button search-clear" id="search-clear-mobile" title="清空">
                            <i class="fas fa-times-circle fa-fw"></i>
                        </a>
                        <span class="search-button search-loading" id="search-loading-mobile">
                            <i class="fas fa-spinner fa-fw fa-spin"></i>
                        </span>
                    </div>
                    <a href="javascript:void(0);" class="search-cancel" id="search-cancel-mobile">
                        取消
                    </a>
                </div><a class="menu-item" href="/posts/" title="">所有文章</a><a class="menu-item" href="/tags/" title="">标签</a><a class="menu-item" href="/categories/" title="">分类</a><a class="menu-item" href="https://github.com/dou-chi" title="" rel="noopener noreffer" target="_blank">github</a><a class="menu-item" href="https://gitee.com/dou-chi" title="" rel="noopener noreffer" target="_blank">gitee</a><a href="javascript:void(0);" class="menu-item theme-switch" title="切换主题">
                <i class="fas fa-adjust fa-fw"></i>
            </a></div>
    </div>
</header>
<div class="search-dropdown desktop">
    <div id="search-dropdown-desktop"></div>
</div>
<div class="search-dropdown mobile">
    <div id="search-dropdown-mobile"></div>
</div>
<main class="main">
                <div class="container"><div class="toc" id="toc-auto">
            <h2 class="toc-title">目录</h2>
            <div class="toc-content always-active" id="toc-content-auto"></div>
        </div><article class="page single"><h1 class="single-title animated flipInX">在Activiti中实现动态流程（修改流程图重新发布后对正在运行的流程生效）</h1><div class="post-meta">
            <div class="post-meta-line"><span class="post-author"><a href="/" title="Author" rel=" author" class="author"><i class="fas fa-user-circle fa-fw"></i>豆是不吃豆豉</a></span>&nbsp;<span class="post-category">收录于 <a href="/categories/activiti/"><i class="far fa-folder fa-fw"></i>Activiti</a></span></div>
            <div class="post-meta-line"><i class="far fa-calendar-alt fa-fw"></i>&nbsp;<time datetime="2020-12-17">2020-12-17</time>&nbsp;<i class="fas fa-pencil-alt fa-fw"></i>&nbsp;约 1109 字&nbsp;
                <i class="far fa-clock fa-fw"></i>&nbsp;预计阅读 3 分钟&nbsp;</div>
        </div><div class="details toc" id="toc-static"  kept="">
                <div class="details-summary toc-title">
                    <span>目录</span>
                    <span><i class="details-icon fas fa-angle-right"></i></span>
                </div>
                <div class="details-content toc-content" id="toc-content-static"><nav id="TableOfContents">
  <ul>
    <li>
      <ul>
        <li><a href="#需求">需求</a></li>
        <li><a href="#实现思路">实现思路</a>
          <ul>
            <li><a href="#原理分析">原理分析</a></li>
            <li><a href="#代码">代码</a></li>
          </ul>
        </li>
      </ul>
    </li>
  </ul>
</nav></div>
            </div><div class="content" id="content"><h2 id="需求">需求</h2>
<ul>
<li>
<p>支持在线动态修改流程图</p>
</li>
<li>
<p>修改流程图发布后对正在运行的流程也要生效</p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://i.loli.net/2020/12/17/WLkNumAb7T91M6G.png"
        data-srcset="https://i.loli.net/2020/12/17/WLkNumAb7T91M6G.png, https://i.loli.net/2020/12/17/WLkNumAb7T91M6G.png 1.5x, https://i.loli.net/2020/12/17/WLkNumAb7T91M6G.png 2x"
        data-sizes="auto"
        alt="https://i.loli.net/2020/12/17/WLkNumAb7T91M6G.png"
        title="修改前流程" /></p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://i.loli.net/2020/12/17/yhgS7p8JqXwnI2Y.png"
        data-srcset="https://i.loli.net/2020/12/17/yhgS7p8JqXwnI2Y.png, https://i.loli.net/2020/12/17/yhgS7p8JqXwnI2Y.png 1.5x, https://i.loli.net/2020/12/17/yhgS7p8JqXwnI2Y.png 2x"
        data-sizes="auto"
        alt="https://i.loli.net/2020/12/17/yhgS7p8JqXwnI2Y.png"
        title="修改前A流程实时流程.PNG" /></p>
<p>修改后同样一个未审批完成的任务的<code>实时流程图</code></p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://i.loli.net/2020/12/17/uvXJAIzsYpKN4C9.png"
        data-srcset="https://i.loli.net/2020/12/17/uvXJAIzsYpKN4C9.png, https://i.loli.net/2020/12/17/uvXJAIzsYpKN4C9.png 1.5x, https://i.loli.net/2020/12/17/uvXJAIzsYpKN4C9.png 2x"
        data-sizes="auto"
        alt="https://i.loli.net/2020/12/17/uvXJAIzsYpKN4C9.png"
        title="修改后流程.PNG" /></p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://i.loli.net/2020/12/17/oFZ4cOG5dKgSpTP.png"
        data-srcset="https://i.loli.net/2020/12/17/oFZ4cOG5dKgSpTP.png, https://i.loli.net/2020/12/17/oFZ4cOG5dKgSpTP.png 1.5x, https://i.loli.net/2020/12/17/oFZ4cOG5dKgSpTP.png 2x"
        data-sizes="auto"
        alt="https://i.loli.net/2020/12/17/oFZ4cOG5dKgSpTP.png"
        title="修改后A流程实时流程.PNG" /></p>
</li>
</ul>
<h2 id="实现思路">实现思路</h2>
<ul>
<li>从流程模型表<code>act_re_model</code>中加载流程模型，使用流程设计器修改修改流程。</li>
<li>调用<code>activiti</code>的API部署新的流程。</li>
<li>根据流程定义Key查找正在运行的流程定义。</li>
<li>根据流程定义文件替换BPMN文件</li>
</ul>
<h3 id="原理分析">原理分析</h3>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://i.loli.net/2020/12/17/Ajvz9qaJNRkcTS1.png"
        data-srcset="https://i.loli.net/2020/12/17/Ajvz9qaJNRkcTS1.png, https://i.loli.net/2020/12/17/Ajvz9qaJNRkcTS1.png 1.5x, https://i.loli.net/2020/12/17/Ajvz9qaJNRkcTS1.png 2x"
        data-sizes="auto"
        alt="https://i.loli.net/2020/12/17/Ajvz9qaJNRkcTS1.png"
        title="act_dynamic_process.PNG" /></p>
<p>流程引擎中是根据<code>act_ge_bytearray</code>中存储的BPMN二进制信息知道流程的走向的，所以，实现思路就是<code>拿新的BPMN二进制文件替换旧的BPMN文件</code>即可实现新的流程应用到新的流程中。</p>
<h3 id="代码">代码</h3>
<p>注意！！：需要清除<code>BpmnModelCache</code>和<code>ProcessDefinitionCache</code>否则不生效</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span><span class="lnt">16
</span><span class="lnt">17
</span><span class="lnt">18
</span><span class="lnt">19
</span><span class="lnt">20
</span><span class="lnt">21
</span><span class="lnt">22
</span><span class="lnt">23
</span><span class="lnt">24
</span><span class="lnt">25
</span><span class="lnt">26
</span><span class="lnt">27
</span><span class="lnt">28
</span><span class="lnt">29
</span><span class="lnt">30
</span><span class="lnt">31
</span><span class="lnt">32
</span><span class="lnt">33
</span><span class="lnt">34
</span><span class="lnt">35
</span><span class="lnt">36
</span><span class="lnt">37
</span><span class="lnt">38
</span><span class="lnt">39
</span><span class="lnt">40
</span><span class="lnt">41
</span><span class="lnt">42
</span><span class="lnt">43
</span><span class="lnt">44
</span><span class="lnt">45
</span><span class="lnt">46
</span><span class="lnt">47
</span><span class="lnt">48
</span><span class="lnt">49
</span><span class="lnt">50
</span><span class="lnt">51
</span><span class="lnt">52
</span><span class="lnt">53
</span><span class="lnt">54
</span><span class="lnt">55
</span><span class="lnt">56
</span><span class="lnt">57
</span><span class="lnt">58
</span><span class="lnt">59
</span><span class="lnt">60
</span><span class="lnt">61
</span><span class="lnt">62
</span><span class="lnt">63
</span><span class="lnt">64
</span><span class="lnt">65
</span><span class="lnt">66
</span><span class="lnt">67
</span><span class="lnt">68
</span><span class="lnt">69
</span><span class="lnt">70
</span><span class="lnt">71
</span><span class="lnt">72
</span><span class="lnt">73
</span><span class="lnt">74
</span><span class="lnt">75
</span><span class="lnt">76
</span><span class="lnt">77
</span><span class="lnt">78
</span><span class="lnt">79
</span><span class="lnt">80
</span><span class="lnt">81
</span><span class="lnt">82
</span><span class="lnt">83
</span><span class="lnt">84
</span><span class="lnt">85
</span><span class="lnt">86
</span><span class="lnt">87
</span><span class="lnt">88
</span><span class="lnt">89
</span><span class="lnt">90
</span><span class="lnt">91
</span><span class="lnt">92
</span><span class="lnt">93
</span><span class="lnt">94
</span><span class="lnt">95
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-java" data-lang="java"><span class="c1">// 相关的包
</span><span class="c1"></span><span class="kn">import</span> <span class="nn">com.fasterxml.jackson.databind.ObjectMapper</span><span class="o">;</span>
<span class="kn">import</span> <span class="nn">com.fasterxml.jackson.databind.JsonNode</span><span class="o">;</span>
<span class="kn">import</span> <span class="nn">org.activiti.engine.RepositoryService</span><span class="o">;</span>
<span class="kn">import</span> <span class="nn">org.activiti.engine.impl.persistence.entity.ResourceEntity</span><span class="o">;</span>
<span class="c1">///////// Class 省略----------
</span><span class="c1"></span>    <span class="nd">@Autowired</span>
    <span class="kd">private</span> <span class="n">RepositoryService</span> <span class="n">repositoryService</span><span class="o">;</span>
<span class="cm">/**
</span><span class="cm">     * 部署流程
</span><span class="cm">     *
</span><span class="cm">     * @param modelId 模型id
</span><span class="cm">     * @return result
</span><span class="cm">     */</span>
    <span class="nd">@Override</span>
    <span class="kd">public</span> <span class="n">Result</span><span class="o">&lt;</span><span class="n">Object</span><span class="o">&gt;</span> <span class="nf">deployProcess</span><span class="o">(</span><span class="n">String</span> <span class="n">modelId</span><span class="o">)</span> <span class="o">{</span>

        <span class="n">Model</span> <span class="n">modelData</span> <span class="o">=</span> <span class="n">repositoryService</span><span class="o">.</span><span class="na">getModel</span><span class="o">(</span><span class="n">modelId</span><span class="o">);</span>
        <span class="c1">// bpmn的json格式
</span><span class="c1"></span>        <span class="kt">byte</span><span class="o">[]</span> <span class="n">jsonBytes</span> <span class="o">=</span> <span class="n">repositoryService</span><span class="o">.</span><span class="na">getModelEditorSource</span><span class="o">(</span><span class="n">modelId</span><span class="o">);</span>
        <span class="k">try</span> <span class="o">{</span>
            <span class="c1">// 转成json节点对象
</span><span class="c1"></span>            <span class="n">JsonNode</span> <span class="n">modelNode</span> <span class="o">=</span> <span class="k">new</span> <span class="n">ObjectMapper</span><span class="o">().</span><span class="na">readTree</span><span class="o">(</span><span class="n">jsonBytes</span><span class="o">);</span>
            <span class="c1">// 转成Bpmn
</span><span class="c1"></span>            <span class="n">BpmnModel</span> <span class="n">model</span> <span class="o">=</span> <span class="k">new</span> <span class="n">BpmnJsonConverter</span><span class="o">().</span><span class="na">convertToBpmnModel</span><span class="o">(</span><span class="n">modelNode</span><span class="o">);</span>

            <span class="k">if</span><span class="o">(</span><span class="n">model</span><span class="o">.</span><span class="na">getProcesses</span><span class="o">().</span><span class="na">isEmpty</span><span class="o">()){</span>
                <span class="k">return</span> <span class="n">Result</span><span class="o">.</span><span class="na">error</span><span class="o">(</span><span class="s">&#34;模型不符要求，请至少设计一条主线流程&#34;</span><span class="o">);</span>
            <span class="o">}</span>
            <span class="c1">// 转成二进制
</span><span class="c1"></span>            <span class="kt">byte</span><span class="o">[]</span> <span class="n">bpmnBytes</span> <span class="o">=</span> <span class="k">new</span> <span class="n">BpmnXMLConverter</span><span class="o">().</span><span class="na">convertToXML</span><span class="o">(</span><span class="n">model</span><span class="o">);</span>
            <span class="c1">// 部署发布模型流程
</span><span class="c1"></span>            <span class="n">String</span> <span class="n">processName</span> <span class="o">=</span><span class="n">modelData</span><span class="o">.</span><span class="na">getName</span><span class="o">()</span> <span class="o">+</span> <span class="s">&#34;.bpmn20.xml&#34;</span><span class="o">;</span>

            <span class="c1">// 部署流程
</span><span class="c1"></span>            <span class="n">Deployment</span> <span class="n">deployment</span> <span class="o">=</span> <span class="n">repositoryService</span><span class="o">.</span><span class="na">createDeployment</span><span class="o">()</span>
                    <span class="o">.</span><span class="na">name</span><span class="o">(</span><span class="n">modelData</span><span class="o">.</span><span class="na">getName</span><span class="o">())</span>
                    <span class="o">.</span><span class="na">addString</span><span class="o">(</span><span class="n">processName</span><span class="o">,</span> <span class="k">new</span> <span class="n">String</span><span class="o">(</span><span class="n">bpmnBytes</span><span class="o">,</span> <span class="s">&#34;UTF-8&#34;</span><span class="o">))</span>
                    <span class="o">.</span><span class="na">deploy</span><span class="o">();</span>

            <span class="c1">// 获取元数据信息
</span><span class="c1"></span>            <span class="n">String</span> <span class="n">metaInfo</span> <span class="o">=</span> <span class="n">modelData</span><span class="o">.</span><span class="na">getMetaInfo</span><span class="o">();</span>
            <span class="n">JSONObject</span> <span class="n">metaInfoMap</span> <span class="o">=</span> <span class="n">JSON</span><span class="o">.</span><span class="na">parseObject</span><span class="o">(</span><span class="n">metaInfo</span><span class="o">);</span>
            
            <span class="c1">// 获取图片二进制
</span><span class="c1"></span>            <span class="kt">byte</span><span class="o">[]</span> <span class="n">imgBytes</span> <span class="o">=</span> <span class="n">repositoryService</span><span class="o">.</span><span class="na">getModelEditorSourceExtra</span><span class="o">(</span><span class="n">modelId</span><span class="o">);</span>

            <span class="c1">// 同时应用到正在运行中的流程
</span><span class="c1"></span>            <span class="k">this</span><span class="o">.</span><span class="na">updateProcdef</span><span class="o">(</span><span class="n">modelData</span><span class="o">.</span><span class="na">getKey</span><span class="o">(),</span> <span class="n">bpmnBytes</span><span class="o">,</span> <span class="n">imgBytes</span><span class="o">);</span>

        <span class="o">}</span> <span class="k">catch</span> <span class="o">(</span><span class="n">IOException</span> <span class="n">e</span><span class="o">)</span> <span class="o">{</span>
            <span class="n">log</span><span class="o">.</span><span class="na">error</span><span class="o">(</span><span class="s">&#34;部署流程-读取模型数据报错&#34;</span><span class="o">,</span><span class="n">e</span><span class="o">);</span>
            <span class="k">return</span> <span class="n">Result</span><span class="o">.</span><span class="na">error</span><span class="o">(</span><span class="s">&#34;读取模型数据失败,请检查流程&#34;</span><span class="o">);</span>
        <span class="o">}</span> <span class="k">catch</span> <span class="o">(</span><span class="n">XMLException</span> <span class="n">e</span><span class="o">){</span>
            <span class="n">log</span><span class="o">.</span><span class="na">error</span><span class="o">(</span><span class="s">&#34;部署流程-解析xml&#34;</span><span class="o">,</span><span class="n">e</span><span class="o">);</span>
            <span class="k">return</span> <span class="n">Result</span><span class="o">.</span><span class="na">error</span><span class="o">(</span><span class="s">&#34;读取模型数据失败,请检查流程是否正确&#34;</span><span class="o">);</span>
        <span class="o">}</span>

        <span class="k">return</span> <span class="n">Result</span><span class="o">.</span><span class="na">ok</span><span class="o">(</span><span class="s">&#34;部署成功&#34;</span><span class="o">);</span>
    <span class="o">}</span>

    <span class="cm">/**
</span><span class="cm">     * 替换BPMN文件和流程图片
</span><span class="cm">     *	@param processKey 流程定义key
</span><span class="cm">     *  @param xml BPMN文件二进制
</span><span class="cm">     *  @param img 流程图文件二进制
</span><span class="cm">     */</span>
    <span class="nd">@Override</span>
    <span class="kd">public</span> <span class="kt">void</span> <span class="nf">updateProcdef</span><span class="o">(</span><span class="n">String</span> <span class="n">processKey</span><span class="o">,</span> <span class="kt">byte</span><span class="o">[]</span> <span class="n">xml</span><span class="o">,</span> <span class="kt">byte</span><span class="o">[]</span> <span class="n">img</span><span class="o">)</span> <span class="o">{</span>
        <span class="c1">// 正在运行中的流程定义信息
</span><span class="c1"></span>        <span class="n">List</span><span class="o">&lt;</span><span class="n">ProcessDefinitionEntity</span><span class="o">&gt;</span> <span class="n">definitions</span> <span class="o">=</span> <span class="n">actCustomService</span><span class="o">.</span><span class="na">queryTaskDeployment</span><span class="o">(</span><span class="n">processKey</span><span class="o">);</span>

        <span class="c1">// 获取配置
</span><span class="c1"></span>        <span class="n">ProcessEngineConfigurationImpl</span> <span class="n">configuration</span> <span class="o">=</span> <span class="o">(</span><span class="n">ProcessEngineConfigurationImpl</span><span class="o">)</span> <span class="n">processEngine</span><span class="o">.</span><span class="na">getProcessEngineConfiguration</span><span class="o">();</span>
        <span class="n">DeploymentManager</span> <span class="n">deploymentManager</span> <span class="o">=</span> <span class="n">configuration</span><span class="o">.</span><span class="na">getDeploymentManager</span><span class="o">();</span>

        <span class="k">for</span> <span class="o">(</span><span class="n">ProcessDefinitionEntity</span> <span class="n">definition</span> <span class="o">:</span> <span class="n">definitions</span><span class="o">)</span> <span class="o">{</span>
            <span class="c1">// 移除缓存！！！！【重要】
</span><span class="c1"></span>            <span class="n">deploymentManager</span><span class="o">.</span><span class="na">getBpmnModelCache</span><span class="o">().</span><span class="na">remove</span><span class="o">(</span><span class="n">definition</span><span class="o">.</span><span class="na">getId</span><span class="o">());</span>
            <span class="n">deploymentManager</span><span class="o">.</span><span class="na">getProcessDefinitionCache</span><span class="o">().</span><span class="na">remove</span><span class="o">(</span><span class="n">definition</span><span class="o">.</span><span class="na">getId</span><span class="o">());</span>
            <span class="c1">// 更新BPMN文件
</span><span class="c1"></span>            <span class="n">ResourceEntity</span> <span class="n">xmlEntity</span> <span class="o">=</span> <span class="k">new</span> <span class="n">ResourceEntity</span><span class="o">();</span>
            <span class="n">xmlEntity</span><span class="o">.</span><span class="na">setDeploymentId</span><span class="o">(</span><span class="n">definition</span><span class="o">.</span><span class="na">getDeploymentId</span><span class="o">());</span>
            <span class="n">xmlEntity</span><span class="o">.</span><span class="na">setName</span><span class="o">(</span><span class="n">definition</span><span class="o">.</span><span class="na">getResourceName</span><span class="o">());</span>
            <span class="n">xmlEntity</span><span class="o">.</span><span class="na">setBytes</span><span class="o">(</span><span class="n">xml</span><span class="o">);</span>
            <span class="n">actCustomService</span><span class="o">.</span><span class="na">updateProcessDefinitionResource</span><span class="o">(</span><span class="n">xmlEntity</span><span class="o">);</span>

            <span class="c1">// 更新流程图片文件
</span><span class="c1"></span>            <span class="n">ResourceEntity</span> <span class="n">imgEntity</span> <span class="o">=</span> <span class="k">new</span> <span class="n">ResourceEntity</span><span class="o">();</span>
            <span class="n">imgEntity</span><span class="o">.</span><span class="na">setDeploymentId</span><span class="o">(</span><span class="n">definition</span><span class="o">.</span><span class="na">getDeploymentId</span><span class="o">());</span>
            <span class="n">imgEntity</span><span class="o">.</span><span class="na">setName</span><span class="o">(</span><span class="n">definition</span><span class="o">.</span><span class="na">getDiagramResourceName</span><span class="o">());</span>
            <span class="n">imgEntity</span><span class="o">.</span><span class="na">setBytes</span><span class="o">(</span><span class="n">img</span><span class="o">);</span>
            <span class="n">actCustomService</span><span class="o">.</span><span class="na">updateProcessDefinitionResource</span><span class="o">(</span><span class="n">imgEntity</span><span class="o">);</span>
        <span class="o">}</span>
    <span class="o">}</span>
</code></pre></td></tr></table>
</div>
</div><p>``ActCustomService<code>调用更新二进制文件的的</code>Mapper`接口</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span><span class="lnt">7
</span><span class="lnt">8
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-java" data-lang="java"><span class="kd">public</span> <span class="kd">interface</span> <span class="nc">ActCustomMapper</span> <span class="o">{</span>
    <span class="cm">/**
</span><span class="cm">     * 更新流程定义的xml和流程图片
</span><span class="cm">     * @param entity 信息
</span><span class="cm">     * @return 更新条数
</span><span class="cm">     */</span>
    <span class="kt">int</span> <span class="nf">updateProcessDefinitionResource</span><span class="o">(</span><span class="nd">@Param</span><span class="o">(</span><span class="s">&#34;resource&#34;</span><span class="o">)</span> <span class="n">ResourceEntity</span> <span class="n">entity</span><span class="o">);</span>
<span class="o">}</span>
</code></pre></td></tr></table>
</div>
</div><p>SQL</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span><span class="lnt">5
</span><span class="lnt">6
</span><span class="lnt">7
</span><span class="lnt">8
</span><span class="lnt">9
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-xml" data-lang="xml">    <span class="c">&lt;!--更新资源--&gt;</span>
    <span class="nt">&lt;update</span> <span class="na">id=</span><span class="s">&#34;updateProcessDefinitionResource&#34;</span><span class="nt">&gt;</span>
        UPDATE `act_ge_bytearray`
        SET BYTES_ = #{resource.bytes}
        <span class="nt">&lt;where&gt;</span>
            DEPLOYMENT_ID_ = #{resource.deploymentId}
            AND NAME_ = #{resource.name}
        <span class="nt">&lt;/where&gt;</span>
    <span class="nt">&lt;/update&gt;</span>
</code></pre></td></tr></table>
</div>
</div></div><div class="post-footer" id="post-footer">
    <div class="post-info">
        <div class="post-info-line">
            <div class="post-info-mod">
                <span>更新于 2020-12-17</span>
            </div>
            <div class="post-info-license"></div>
        </div>
        <div class="post-info-line">
            <div class="post-info-md"><span>
                            <a class="link-to-markdown" href="/actdynamicprocess/index.md" target="_blank">阅读原始文档</a>
                        </span></div>
            <div class="post-info-share">
                <span><a href="javascript:void(0);" title="分享到 Twitter" data-sharer="twitter" data-url="https://dou-chi.gitee.io/actdynamicprocess/" data-title="在Activiti中实现动态流程（修改流程图重新发布后对正在运行的流程生效）" data-hashtags="Activiti"><i class="fab fa-twitter fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Facebook" data-sharer="facebook" data-url="https://dou-chi.gitee.io/actdynamicprocess/" data-hashtag="Activiti"><i class="fab fa-facebook-square fa-fw"></i></a><a href="javascript:void(0);" title="分享到 WhatsApp" data-sharer="whatsapp" data-url="https://dou-chi.gitee.io/actdynamicprocess/" data-title="在Activiti中实现动态流程（修改流程图重新发布后对正在运行的流程生效）" data-web><i class="fab fa-whatsapp fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Line" data-sharer="line" data-url="https://dou-chi.gitee.io/actdynamicprocess/" data-title="在Activiti中实现动态流程（修改流程图重新发布后对正在运行的流程生效）"><i data-svg-src="/lib/simple-icons/icons/line.min.svg"></i></a><a href="javascript:void(0);" title="分享到 微博" data-sharer="weibo" data-url="https://dou-chi.gitee.io/actdynamicprocess/" data-title="在Activiti中实现动态流程（修改流程图重新发布后对正在运行的流程生效）"><i class="fab fa-weibo fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Myspace" data-sharer="myspace" data-url="https://dou-chi.gitee.io/actdynamicprocess/" data-title="在Activiti中实现动态流程（修改流程图重新发布后对正在运行的流程生效）" data-description="在Activiti中实现动态流程（修改流程图重新发布后对正在运行的流程生效）"><i data-svg-src="/lib/simple-icons/icons/myspace.min.svg"></i></a><a href="javascript:void(0);" title="分享到 Blogger" data-sharer="blogger" data-url="https://dou-chi.gitee.io/actdynamicprocess/" data-title="在Activiti中实现动态流程（修改流程图重新发布后对正在运行的流程生效）" data-description="在Activiti中实现动态流程（修改流程图重新发布后对正在运行的流程生效）"><i class="fab fa-blogger fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Evernote" data-sharer="evernote" data-url="https://dou-chi.gitee.io/actdynamicprocess/" data-title="在Activiti中实现动态流程（修改流程图重新发布后对正在运行的流程生效）"><i class="fab fa-evernote fa-fw"></i></a></span>
            </div>
        </div>
    </div>

    <div class="post-info-more">
        <section class="post-tags"><i class="fas fa-tags fa-fw"></i>&nbsp;<a href="/tags/activiti/">Activiti</a></section>
        <section>
            <span><a href="javascript:void(0);" onclick="window.history.back();">返回</a></span>&nbsp;|&nbsp;<span><a href="/">主页</a></span>
        </section>
    </div>

    <div class="post-nav"><a href="/activiti%E4%BA%8C%E5%88%9D%E5%A7%8B%E5%8C%96/" class="prev" rel="prev" title="Activiti（二）初始化"><i class="fas fa-angle-left fa-fw"></i>Activiti（二）初始化</a>
            <a href="/kettle-paging/" class="next" rel="next" title="Kettle循环分页导入数据">Kettle循环分页导入数据<i class="fas fa-angle-right fa-fw"></i></a></div>
</div>
<div id="comments"></div></article></div>
            </main><footer class="footer">
        <div class="footer-container"><div class="footer-line">由 <a href="https://gohugo.io/" target="_blank" rel="noopener noreffer" title="Hugo 0.74.3">Hugo</a> 强力驱动 | 主题 - <a href="https://github.com/dillonzq/LoveIt" target="_blank" rel="noopener noreffer" title="LoveIt 0.2.10"><i class="far fa-kiss-wink-heart fa-fw"></i> LoveIt</a>
                </div><div class="footer-line"><i class="far fa-copyright fa-fw"></i><span itemprop="copyrightYear">2019 - 2021</span><span class="author" itemprop="copyrightHolder">&nbsp;<a href="/" target="_blank">豆是不吃豆豉</a></span></div>
        </div>
    </footer></div>

        <div id="fixed-buttons"><a href="#" id="back-to-top" class="fixed-button" title="回到顶部">
                <i class="fas fa-arrow-up fa-fw"></i>
            </a><a href="#" id="view-comments" class="fixed-button" title="查看评论">
                <i class="fas fa-comment fa-fw"></i>
            </a>
        </div><link rel="stylesheet" href="/lib/katex/katex.min.css"><link rel="stylesheet" href="/lib/katex/copy-tex.min.css"><link rel="stylesheet" href="/lib/cookieconsent/cookieconsent.min.css"><script type="text/javascript" src="/lib/smooth-scroll/smooth-scroll.min.js"></script><script type="text/javascript" src="/lib/autocomplete/autocomplete.min.js"></script><script type="text/javascript" src="/lib/lunr/lunr.min.js"></script><script type="text/javascript" src="/lib/lunr/lunr.stemmer.support.min.js"></script><script type="text/javascript" src="/lib/lunr/lunr.zh.min.js"></script><script type="text/javascript" src="/lib/lazysizes/lazysizes.min.js"></script><script type="text/javascript" src="/lib/clipboard/clipboard.min.js"></script><script type="text/javascript" src="/lib/sharer/sharer.min.js"></script><script type="text/javascript" src="/lib/katex/katex.min.js"></script><script type="text/javascript" src="/lib/katex/auto-render.min.js"></script><script type="text/javascript" src="/lib/katex/copy-tex.min.js"></script><script type="text/javascript" src="/lib/katex/mhchem.min.js"></script><script type="text/javascript" src="/lib/cookieconsent/cookieconsent.min.js"></script><script type="text/javascript">window.config={"code":{"copyTitle":"复制到剪贴板","maxShownLines":100},"comment":{},"cookieconsent":{"content":{"dismiss":"同意","link":"了解更多","message":"本网站使用 Cookies 来改善您的浏览体验."},"enable":true,"palette":{"button":{"background":"#f0f0f0"},"popup":{"background":"#1aa3ff"}},"theme":"edgeless"},"math":{"delimiters":[{"display":true,"left":"$$","right":"$$"},{"display":true,"left":"\\[","right":"\\]"},{"display":false,"left":"$","right":"$"},{"display":false,"left":"\\(","right":"\\)"}],"strict":false},"search":{"highlightTag":"em","lunrIndexURL":"/index.json","lunrLanguageCode":"zh","lunrSegmentitURL":"/lib/lunr/lunr.segmentit.js","maxResultLength":10,"noResultsFound":"没有找到结果","snippetLength":50,"type":"lunr"}};</script><script type="text/javascript" src="/js/theme.min.js"></script></body>
</html>
